package com.ruoyi.decision.service.impl;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.decision.mapper.UserTaskStrategyMapper;
import com.ruoyi.decision.domain.UserTaskStrategy;
import com.ruoyi.decision.service.IUserTaskStrategyService;

/**
 * 用户，预案，策略中间Service业务层处理
 * 
 * @author zbw
 * @date 2022-08-19
 */
@Service
public class UserTaskStrategyServiceImpl implements IUserTaskStrategyService 
{
    @Autowired
    private UserTaskStrategyMapper userTaskStrategyMapper;

    /**
     * 查询用户，预案，策略中间
     * 
     * @param id 用户，预案，策略中间主键
     * @return 用户，预案，策略中间
     */
    @Override
    public UserTaskStrategy selectUserTaskStrategyById(String id)
    {
        return userTaskStrategyMapper.selectUserTaskStrategyById(id);
    }

    /**
     * 查询用户，预案，策略中间列表
     * 
     * @param userTaskStrategy 用户，预案，策略中间
     * @return 用户，预案，策略中间
     */
    @Override
    public List<UserTaskStrategy> selectUserTaskStrategyList(UserTaskStrategy userTaskStrategy)
    {
        return userTaskStrategyMapper.selectUserTaskStrategyList(userTaskStrategy);
    }

    /**
     * 新增用户，预案，策略中间
     * 
     * @param userTaskStrategy 用户，预案，策略中间
     * @return 结果
     */
    @Override
    public int insertUserTaskStrategy(UserTaskStrategy userTaskStrategy)
    {
        UserTaskStrategy userTaskStrategy1 = new UserTaskStrategy();
        try {
            for (String strategyID : userTaskStrategy.getStrategyIds()) {
                String id = UUID.randomUUID().toString().toLowerCase(Locale.ROOT).replace("-","");
                userTaskStrategy1.setId(id);
                userTaskStrategy1.setUserId(userTaskStrategy.getUserId());
                userTaskStrategy1.setTaskId(userTaskStrategy.getTaskId());
                userTaskStrategy1.setStrategyId(strategyID);
                userTaskStrategyMapper.insertUserTaskStrategy(userTaskStrategy1);
            }
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 修改用户，预案，策略中间
     * 
     * @param userTaskStrategy 用户，预案，策略中间
     * @return 结果
     */
    @Override
    public int updateUserTaskStrategy(UserTaskStrategy userTaskStrategy)
    {
        return userTaskStrategyMapper.updateUserTaskStrategy(userTaskStrategy);
    }

    /**
     * 批量删除用户，预案，策略中间
     * 
     * @param ids 需要删除的用户，预案，策略中间主键
     * @return 结果
     */
    @Override
    public int deleteUserTaskStrategyByIds(String[] ids)
    {
        return userTaskStrategyMapper.deleteUserTaskStrategyByIds(ids);
    }

    /**
     * 删除用户，预案，策略中间信息
     * 
     * @param id 用户，预案，策略中间主键
     * @return 结果
     */
    @Override
    public int deleteUserTaskStrategyById(String id)
    {
        return userTaskStrategyMapper.deleteUserTaskStrategyById(id);
    }
}
